package hot100.logos61To70;

/**
 * @author logos
 * date 2025/7/16 12:58
 * @version v1.0
 * @Package hot100.logos61To70
 */
public class logos64 {

    /**
     * 64. 搜索二维矩阵
     * https://leetcode.cn/problems/search-a-2d-matrix/description/?envType=study-plan-v2&envId=top-100-liked
     */

    class Solution {
        public boolean searchMatrix(int[][] matrix, int target) {
            int n = matrix.length;
            int m = matrix[0].length;
            int i = 0;
            int j = m - 1;
            while (i < n && j >= 0) {
                if (matrix[i][j] == target) {
                    return true;
                } else if (matrix[i][j] > target) {
                    j--;
                } else {
                    i++;
                }
            }
            return false;
        }
    }
}
